//打开支付宝，搜索 736385254 领红包，消费可抵扣，我还能得推广费，免费支持我继续更新博客创作吧~
importClass("android.content.pm.PackageManager");
importClass("android.provider.Settings");
const myPackageName = context.getPackageName();
if (!auto.rootInActiveWindow) {
    if (checkPermission("android.permission.WRITE_SECURE_SETTINGS")) {
        openAccessibility();
    } else {
        if ($shell.checkAccess("adb")) {
            shell("pm grant " + myPackageName + " android.permission.WRITE_SECURE_SETTINGS", {
                adb: true,
            });
            toastLog("adb授权成功");
            openAccessibility();
        } else {
            if ($shell.checkAccess("root")) {
                shell("pm grant " + myPackageName + " android.permission.WRITE_SECURE_SETTINGS", {
                    root: true,
                });
                toastLog("root授权成功");
                openAccessibility();
            } else {
                console.info("\n也可使用WRITE_SECURE_SETTINGS权限开启无障碍服务\n授权代码已复制，使用adb激活");
                setClip("adb shell pm grant " + myPackageName + " android.permission.WRITE_SECURE_SETTINGS");
                app.startActivity({
                    action: "android.settings.ACCESSIBILITY_SETTINGS",
                });
            }
        }
    }
}
function openAccessibility() {
    let mServices = ":" + myPackageName + "/com.stardust.autojs.core.accessibility.AccessibilityService";
    let enabledServices = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES).replace(new RegExp(mServices, "g"), "");
    Settings.Secure.putString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "");
    //Settings.Secure.putString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, enabledServices);
    Settings.Secure.putString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, enabledServices + mServices);
}

function checkPermission(permission) {
    pm = context.getPackageManager();
    return PackageManager.PERMISSION_GRANTED == pm.checkPermission(permission, context.getPackageName().toString());
}
setTimeout(()=>{
    log(auto.service)
},500)